import request from '@/utils/request'
import { tansParams } from '@/utils/index'
// 获取所有的Role
export function getAll() {
  return request({
    url: 'api/sys/roles/all',
    method: 'get'
  })
}

export function add(data) {
  return request({
    url: 'api/sys/roles/insert',
    method: 'post',
    data
  })
}

export function get(id) {
  return request({
    url: 'api/sys/roles/' + id,
    method: 'get'
  })
}

export function getRolePrivilege(id) {
  return request({
    url: 'api/sys/roles/getRolePrivilege/' + id,
    method: 'get'
  })
}

export function del(ids) {
  return request({
    url: 'api/sys/roles',
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'api/sys/roles/update',
    method: 'post',
    data
  })
}

export function editPrivileges(data) {
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    url: 'api/sys/roles/privileges',
    method: 'Post',
    data: data,
    transformRequest: [(data) = > {
      return tansParams(data)
    }
]
})
}

export default { add, edit, del, get, editPrivileges, getRolePrivilege }
